<template>
	<view style="padding-bottom: 150rpx;">
		<goods-order-address :address="address"></goods-order-address>

		<!-- 商品详情 -->
		<view class="u-m-t-20">
			<view class="u-p-30 bg-white">
				<block v-for="(v,indey) in shopList" :key='indey'>
					<goods-order-goods-item :item="v"></goods-order-goods-item>
				</block>
				<view class="flex align-center u-p-y-10 u-border-bottom">
					<u-form ref="uForm" class="flex-1">
						<u-form-item labelWidth="120" label="买家留言:" :borderBottom="false">
							<u-input class="flex-1" v-model="formData.note" placeholder="建议留言前先与商家沟通确认（50字内）" type="textarea"
							placeholderStyle="font-size: 24rpx; color: #999" maxlength="50"/>
						</u-form-item>
					</u-form>
				</view>
				<view class="">
					<u-cell-item title="购买数量" :arrow="false">
						<view class="" slot="right-icon">
							<u-number-box v-model="formData.goods_num" :min="1" @minus="_orderBuyNow" @plus="_orderBuyNow" @blur="_orderBuyNow"></u-number-box>
						</view>
					</u-cell-item>
					<u-cell-item title="商品金额" :value="'¥' + details.order_total_price" :arrow="false"></u-cell-item>
					<u-cell-item title="优惠金额" :value="'¥'+ details.reduce_price" :arrow="false" :value-style="{color:'#da5961'}"></u-cell-item>
					<u-cell-item title="运费" :value="'¥'+ details.express_price" :arrow="false"></u-cell-item>
					<u-cell-item title="实付金额" :value="'¥'+ details.order_pay_price" :arrow="false"></u-cell-item>
				</view>
			</view>
		</view>
		
		<view class="position-fixed left-0 right-0 bottom-0" style="z-index: 2;">
      <view class="safe-bottom bg-white">
        <view class="flex align-center justify-between u-p-x-30 bg-white border-top" style="height: 100rpx;">
        	<view class="">
        		<text class="u-font-28 u-m-r-20">实付金额</text> 
        		<text class="u-font-28 text-danger font-weight-bold">¥{{details.order_pay_price}}</text> 
        	</view>
        	<view class="">
        		<dy-button width="200rpx" size="default" @click="sureOrder">立即支付</dy-button>
        	</view>
        </view>
      </view>
			
		</view>
	</view>
</template>

<script>
	import { GroupCenterApi } from '@/api/serves.js'
	export default {
		data() {
			return {
				is_ct: '',               // 拼团还是参团
				formData: {
					groups_goods_id: '',
					groups_team_id: '',
					goods_num:1,
					note:'',
				},
				details: {},
				address: { Area: null},  // 收货地址
				shopList: [],            // 店铺商品list
				note: [],                // 备注
			};
		},
    onUnload() {
    	uni.$off('addressClick')
    },
		onLoad(options) {
      uni.$on('addressClick',()=> {
        this._orderBuyNow()
      })
			console.log('options', options);
			this.formData.groups_goods_id = options.groups_goods_id
			this.formData.groups_team_id = options.groups_team_id || ''
			console.log('this.formData', this.formData);
			// let orderInfo = JSON.parse(options.info)
			// this.is_ct = options.is_ct // 1 为参团 2 为拼团
			// if(this.is_ct == 1) {
			// 	this.formData.ct_id = orderInfo.ct_id
			// }else {
			// 	this.formData.pt_id = orderInfo.pt_id
			// }
			// this.live_id = orderInfo.live_id
			// this.formData.goods_id = orderInfo.goods_id
			// this.formData.goods_sku_id = orderInfo.goods_sku_id
			this._orderBuyNow()
		},
		methods:{
			_orderBuyNow() {
				GroupCenterApi.orderBuy(this.formData).then(res => {
					console.log('订单详情', res)
					if (res.code == 1) {
						this.details = res.data
						this.address = res.data.address
						if (this.address) {
							this.address.Area = Object.values(this.address.Area);
						}
						this.shopList = res.data.goods_list
					}
				})
			},
			sureOrder() {
				uni.showLoading()
				GroupCenterApi.buyNow_pay2(this.formData).then((res)=> {
					console.log('商品下单成功，待支付', res);
					uni.hideLoading()
					if(res.code == 1) {
						let params = {
						  order_no: res.data.order_no,
						  from: 'group',
						}
						uni.redirectTo({
							url: '/pages/goodsDetail/goodsOrderPay/goodsOrderPay?orderInfo=' + JSON.stringify(params)
						})
					}else {
						this.$Toast(res.msg)
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
.u-cell[data-v-65423b64] {
	padding: 15rpx 0;
}
::v-deep .u-cell_title[data-v-65423b64] {
	font-weight: bold;
}
.u-field[data-v-1c764f86] {
	padding-left: 0;
	padding-right: 0;
}
</style>
